#include "RaiderBullets.h"
#include <math.h>
#define PI 3.14159265
#include <iostream>

#pragma region Base
RaiderBullets::RaiderBullets() {
}


RaiderBullets::~RaiderBullets() {
}
#pragma endregion


#pragma region Publics
void RaiderBullets::initialize(sf::RenderWindow* window, float angle, sf::Vector2f raiderPos, sf::Texture* img) {
	m_angle = angle;
	m_renderWindow = window;
	
	m_bulletImg = img;
	m_bulletSprite = new sf::Sprite();

	m_bulletSprite->setTexture(*m_bulletImg);

	m_bulletSprite->setPosition(raiderPos);
	
	m_bulletSprite->setOrigin(6.0f, 12.0f);
	m_bulletSprite->setRotation(m_angle * 180 / PI * 1 + 180);
	m_clock = new sf::Clock();

	speed = 600.0f;
	
	//std::cout << m_bulletSprite->getRotation() << std::endl;
}

void RaiderBullets::update() {
	timeSinceLastFrame = m_clock->restart();

	m_bulletSprite->move(speed * cos(m_angle) * timeSinceLastFrame.asSeconds(),
		speed * sin(m_angle) * timeSinceLastFrame.asSeconds());

	m_renderWindow->draw(*m_bulletSprite);

}



void RaiderBullets::cleanup() {

	delete m_bulletSprite;
	delete m_clock;	
}
#pragma endregion